package com.ljt.kotlinandmvvm.main.fragment

import android.content.Intent
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.GridLayoutManager
import com.ljt.base.fragment.BaseFragment
import com.ljt.kotlinandmvvm.R
import com.ljt.kotlinandmvvm.databinding.FragmentMyBinding
import com.ljt.kotlinandmvvm.login.LoginActivity
import com.ljt.kotlinandmvvm.main.adapter.RecommendToYouAdapter
import com.ljt.kotlinandmvvm.orderfrom.activity.OrderFromActivity
import com.ljt.kotlinandmvvm.recharge.RechargeActivity
import kotlinx.android.synthetic.main.draw_module_title.view.*

/**
 * @auther :lujiantao
 * @date :2024/4/29 12:38 PM
 * @desc :我的
 */
class MyFragment: BaseFragment(), View.OnClickListener {

    private lateinit var binding: FragmentMyBinding
    private var listStr:ArrayList<String> = ArrayList()
    private lateinit var recommmendToYouAdapter: RecommendToYouAdapter

    companion object{
        fun newInstance() = MyFragment()
    }

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        binding = FragmentMyBinding.inflate(layoutInflater) // 缺失的是这一行
        initView()
        return binding.root
    }


    fun initView() {
        if (binding != null) {
            binding.ilModuleTitle.tvModuleTitle.text = "我的"
            binding.ilModuleTitle.ivModuleBack.visibility = View.GONE
            binding.tvModuleUnLogin.setOnClickListener(this)
            binding.llModuleRecharge.setOnClickListener(this)
            binding.tvModuleViewAll.setOnClickListener(this)
            binding.llModuleUnpaid.setOnClickListener(this)
            binding.llModulePaid.setOnClickListener(this)
            binding.llModuleCompleted.setOnClickListener(this)
            binding.llModuleCanceled.setOnClickListener(this)
            binding.llModuleRefunded.setOnClickListener(this)


            //为您推荐
            listStr.add("神仙鸡")
            listStr.add("神仙豆腐")
            listStr.add("白玉汤")
            recommmendToYouAdapter = RecommendToYouAdapter(listStr)
            binding.rlModule.layoutManager = GridLayoutManager(requireActivity(),2)
            binding.rlModule.adapter = recommmendToYouAdapter

        }
    }

    override fun onClick(v: View?) {
        var id = v?.id
        if (id == R.id.tvModuleUnLogin){
            startActivity(Intent(requireActivity(), LoginActivity::class.java))
        }else if (id == R.id.llModuleRecharge){
            startActivity(Intent(requireActivity(), RechargeActivity::class.java))
        }else if (id == R.id.tvModuleViewAll){
            startActivity(Intent(requireActivity(), OrderFromActivity::class.java).putExtra("module_type",0))
        }else if (id == R.id.llModuleUnpaid){
            startActivity(Intent(requireActivity(), OrderFromActivity::class.java).putExtra("module_type",1))
        }else if (id == R.id.llModulePaid){
            startActivity(Intent(requireActivity(), OrderFromActivity::class.java).putExtra("module_type",2))
        }else if (id == R.id.llModuleCanceled){
            startActivity(Intent(requireActivity(), OrderFromActivity::class.java).putExtra("module_type",3))
        }else if (id == R.id.llModuleRefunded){
            startActivity(Intent(requireActivity(), OrderFromActivity::class.java).putExtra("module_type",4))
        }
    }
}